﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class Login : System.Web.UI.Page
{
    private static string sqlStr = "Integrated Security=SSPI;Data Source=(local);initial catalog=tsmanager";
    SqlConnection con = new SqlConnection(sqlStr);

    protected void Page_Load(object sender, EventArgs e)
    {
     
    }

    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Response.Redirect("Register.aspx");
    }

    protected void Button1_Click(object sender, EventArgs e)
    {

            string str1 = TextBox1.Text.Trim();
            string sql = "";
            if (RadioButton1.Checked)
                sql = "select * from Readers where ReadersNAME='" + str1 + "'";
            else if (RadioButton2.Checked)
                sql = "select * from librarian where LibrarianNAME='" + str1 + "'";
            try{
                if (con.State == ConnectionState.Closed)
                {
                    con.Open();
                }
                SqlCommand SC = new SqlCommand(sql, con);
                SqlDataReader dr = SC.ExecuteReader();
            }catch(Exception ex){
                
            }
            if (dr.Read())
            {
                Session["name"] = str1;

                if (RadioButton1.Checked)
                {
                    Session["id"] = dr["ReadersID"].ToString();
                    Response.Redirect("User\\shenfen.aspx");
                }
                else if (RadioButton2.Checked)
                {
                    Session["glyid"] = dr["librarianID"].ToString();
                    Response.Redirect("Manager\\shenfen.aspx");
                }
            }
            else
            {
                Response.Write("<script language=javascript>alert('用户名错误！')</script>");
            }
            dr.Close();
     
}